﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Globalization;
using System.Text.RegularExpressions;

namespace TotalSystems.Core.Controls
{
    public partial class LabeledCombo : UserControl
    {
        #region Constractor
        public LabeledCombo()
        {
            InitializeComponent();
        }
        #endregion

        #region  DependencyProperty
        public static  DependencyProperty LableWidthProperty = DependencyProperty.Register("LableWidth",          //Name
        typeof(double),       //Type
        typeof(LabeledCombo),     //Owner of the Property
        new PropertyMetadata(125d, new PropertyChangedCallback(OnLableWidthPropertyChanged))
        );

        public static DependencyProperty ItemSourceProperty = DependencyProperty.Register("ItemSource",          //Name
        typeof(string),       //Type
        typeof(LabeledCombo),     //Owner of the Property
        new PropertyMetadata((string)null, new PropertyChangedCallback(OnItemSourcePropertyChanged))
        );

        public static DependencyProperty LabelTextProperty = DependencyProperty.Register("LabelText",
            typeof(string),
            typeof(LabeledCombo),
            new PropertyMetadata("Label", new PropertyChangedCallback(OnLabelTextChanged))
            );
        #endregion

        #region  CallBack
        private static void OnLableWidthPropertyChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            var comboBoxTextCtrl = sender as LabeledCombo;
            if (e.NewValue == null )
            {
                comboBoxTextCtrl.comComboBox.Width = (double)e.NewValue;
                comboBoxTextCtrl.lblMandatory.Width = 0;// (double)e.NewValue;
                comboBoxTextCtrl.lblMandatory.Visibility = System.Windows.Visibility.Collapsed;
            }
        }

        private static void OnItemSourcePropertyChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            //var comboBoxTextCtrl = sender as LabeledCombo;
            //if (e.NewValue != null)
            //    comboBoxTextCtrl.textBox1.Text = (string)e.NewValue;
        }

        private static void OnLabelTextChanged(object sender, DependencyPropertyChangedEventArgs e)
        { }
        #endregion

        #region  Property
        public double LableWidth
        {
            get { return (double)GetValue(LableWidthProperty); }
            set { SetValue(LableWidthProperty, value); }
        }

        public string LabelText
        {
            get { return (string)GetValue(LabelTextProperty); }
            set { SetValue(LabelTextProperty, value); }
        }

        public string Source
        {
            get { return (string)GetValue(ItemSourceProperty); }
            set { SetValue(ItemSourceProperty, value); }
        }

        private bool _isMandatory;
        public bool IsMandatory
        {
            get { return _isMandatory; }
            set
            {
                _isMandatory = value;
                if (value)
                    lblMandatory.Visibility = System.Windows.Visibility.Visible;
                else
                    lblMandatory.Visibility = System.Windows.Visibility.Collapsed;
            }
        }

        #endregion

    }
}
